<?php

namespace App\Models\Order;

use App\Models\CheckTime;
use App\Models\Common\Media;
use App\Models\OrderSampleParameter;
use App\Models\System\CheckItem;
use App\Models\System\TestLocation;
use App\Models\Traits\HasOperateLog;
use App\Models\User\FamilyUser;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class OrderSample extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    use HasOperateLog;

    protected $table = 'order_samples';

    protected $guarded = [];

    protected $appends = [];

    public function checkTime() : BelongsTo
    {
        return $this->belongsTo(CheckTime::class, 'check_time_id');
    }

    public function goodsOrder() : BelongsTo
    {
        return $this->belongsTo(GoodsOrder::class, 'order_id');
    }

    public function checkItem() : BelongsTo
    {
        return $this->belongsTo(CheckItem::class, 'item_id');
    }

    public function checker() : BelongsTo
    {
        return $this->belongsTo(FamilyUser::class, 'checker_id');
    }

    public function qrcode() : BelongsTo
    {
        return $this->belongsTo(Media::class, 'qrcode_id');
    }

    public function binder() : BelongsTo
    {
        return $this->belongsTo(FamilyUser::class, 'binder_id');
    }

    public function parameters() : HasMany
    {
        return $this->hasMany(OrderSampleParameter::class, 'order_sample_id');
    }

    public function checkPdf() : BelongsTo
    {
        return $this->belongsTo(Media::class, 'check_pdf_id');
    }

    public function testLocation() : BelongsTo
    {
        return $this->belongsTo(TestLocation::class, 'test_location_id');
    }
}
